********************************************************************************
** Do file: g10_sac_regression.do
** First started: June 28, 2022
** Last edited: December 31, 2023

/* Purpose: this do file explores whether treatment predicts school aged children (SAC)

* ITEM MADE: TABLE A.13
*/

********************************************************************************

clear
clear matrix
clear mata
set maxvar 10000

************
** Part I **
************

* Develop a num_520 variable but for endline
use "$esvy_clean/2_educ_indiv.dta", clear
g num_520e = 1
collapse (sum) num_520e, by(hhid)
tempfile num_520e_info
save `num_520e_info'

/* Start with the "key" that identifies who is actually part of the sample, from all the datasets that we use (administrative, survey) */
use "$merged/key_rep.dta", clear
	
* Define down to the sample of interest: those who were sent SMS, responded to SMS, were interacted with from IPA, given the baseline survey, and given endline survey
keep if k_complete_may==1 & k_rolling_list==1 & k_interacted_success==1 & k_surveyed==1 & k_surveyed_end==1

* Merge in num_520e
merge 1:1 hhid using `num_520e_info', keepusing(num_520e)
replace num_520e = 0 if num_520e==.
keep if _merge==3 | _merge==1
drop _merge

drop if treatmenttype_sh=="R T3"

* Create indicator
g yesSACe = (num_520e>0)

* Develop treatment indicators
g anytreat = !(treatmenttype_sh=="R C")
g secured = (treatmenttype_sh=="R T1-L")
g surprise = (treatmenttype_sh=="R T1-U")
g unsecured = (treatmenttype_sh=="R T2-U")

* Outcome mean
sum yesSACe if anytreat==0

* Tests of equality between coefficients
reg yesSACe secured surprise unsecured
test secured = surprise = unsecured
test secured = unsecured

***** TABLE A.13 *****

eststo: reg yesSACe anytreat
eststo: reg yesSACe secured surprise unsecured

esttab using "$tables/sacreg.tex", ///
	b(3) se(3) se replace booktabs star(* .10 ** .05 *** .01) title(Probability of Having Any School-Aged Children On Treatment Assignment\label{sacreg}) ///
	label nodepvars mtitles("Any SAC" "Any SAC") nonotes ///
	varlabels(anytreat_assigned "Pooled" _cons "Constant" locked_assigned "Secured" surprise_assigned "Surprise Unsecured" unlocked_assigned "Unsecured", ///
	elist(anytreat_assigned \addlinespace locked_assigned \addlinespace surprise_assigned \addlinespace unlocked_assigned \addlinespace)) 
eststo clear
